
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Glaccount extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('upload');
		$this->load->library('variable');

	}

	public function index(){
		$this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	 	 $this->load->view($this->session->userdata('formain'),array(
	      	'glLookups'   => $this->wus->getLookupValues()
	    ));
	  	$this->load->view('layouts/footer');
	}

	public function add_Account(){
		$ena = $this->input->post('gl_enabled');
		$data = array(
			':p_trx_type'		=> 'I',
			':p_company_id'		=>	filter_var($this->session->userdata('company_id')),
			':p_acct_code'		=>	filter_var($this->input->post('gl_code'),FILTER_SANITIZE_STRING),
			':p_acct_name'		=>	filter_var($this->input->post('gl_name'),FILTER_SANITIZE_STRING),
			':p_acct_type'		=>	filter_var($this->input->post('gl_type'),FILTER_SANITIZE_STRING),
			':p_sub_type'		=>	filter_var($this->input->post('gl_sub_type'),FILTER_SANITIZE_STRING),
			':p_enable_flag'	=>	($ena == "ok" ? 'Y' : 'N'),
			':p_user_id'		=>	$this->session->userdata('user_id'),
			':p_account_id'		=>  ''
			);
		$this->glaccount_model->save_gl_account($data);
	}

	public function edit_Account(){
		$ena = $this->input->post('gl_enabled_e');
		$data = array(
			':p_trx_type'		=> 'U',
			':p_company_id'		=>	filter_var($this->session->userdata('company_id')),
			':p_acct_code'		=>	filter_var($this->input->post('gl_code_e'),FILTER_SANITIZE_STRING),
			':p_acct_name'		=>	filter_var($this->input->post('gl_name_e'),FILTER_SANITIZE_STRING),
			':p_acct_type'		=>	filter_var($this->input->post('gl_type_e'),FILTER_SANITIZE_STRING),
			':p_sub_type'		=>	filter_var($this->input->post('gl_sub_type_e'),FILTER_SANITIZE_STRING),
			':p_enable_flag'	=>	($ena == "ok" ? 'Y' : 'N'),
			':p_user_id'		=>	$this->session->userdata('user_id'),
			':p_account_id'		=>	$this->input->post('account_id')
		);
		$this->glaccount_model->edit_gl_account($data);
	}

	public function gl_acc_search(){
		$gcode  = $this->input->post('gl_code-s');
		$gname  = $this->input->post('gl_name-s');
		$gtype  = $this->input->post('gl_type-s');
		$gstype = $this->input->post('gl_sub-type-s');
		$gena   = $this->input->post('gl_enabled-s');
		$eflag  = ($gena == 'on' ? 'Y' : 'N');
		$query  = $this->glaccount_model->searchGL($gcode,$gname,$gtype,$gstype,$eflag);
		echo json_encode($query);
	}

	public function add_form(){
		$this->load->view($this->session->userdata('foradd'),array(
	      'glLookups'   => $this->wus->getLookupValues()
	    ));
	}
	public function edit_form($id){
		$query = $this->glaccount_model->getGLdtl($id);
		$this->load->view($this->session->userdata('foredit'),array(
	      'glLookups'   => $this->wus->getLookupValues(),
	      'edit_data'	=> $query
	    ));
	}

	public function view_form($id){
		$query = $this->glaccount_model->getGLdtl($id);
		$this->load->view($this->session->userdata('forview'),array(
	      'glLookups'   => $this->wus->getLookupValues(),
	      'view_data'	=> $query
	    ));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */